<?php
//生成时间2023-03-30 16:32
class ttel{
    static private $s_no=NULL;//工號
    static public function Set_s_no($s_no){
        if(strlen($s_no)<1 || strlen($s_no)>30){
            return "工號的输入字数不在指定范围1~30";
        }
        if(!preg_match("/^([A-Z]|[a-z]|\d)(\d{4,17}|(\d{4,17}[A-Z]\d{0,4}))|(^\d{18}$)|(^\d{17}(\d|X|x)$)$/",$s_no)){
            return "工號的输入格式错误";
        }
        self::$s_no=addslashes($s_no);
        return 1;
    }
    static private $s_tel=NULL;//手機號碼
    static public function Set_s_tel($s_tel){
        if(strlen($s_tel)<1 || strlen($s_tel)>11){
            return "手機號碼的输入字数不在指定范围1~11";
        }
        if(!preg_match("/(^\d{11}$)|(^([6|9])\d{7}$)|(^[6]([8|6])\d{5})/",$s_tel)){
            return "手機號碼的输入格式错误";
        }
        self::$s_tel=addslashes($s_tel);
        return 1;
    }
    static public function Add($db){
        $params=array();
        $sql="insert into t_tel_t(";
        $sql.=self::$s_no!=NULL?"s_no,":'';
        $sql.=self::$s_tel!=NULL?"s_tel,":'';
        $sql=trim($sql,',');
        $sql.=") values (";
        if(self::$s_no!=NULL){
            $sql.="?,";
            array_push($params,self::$s_no);
        }
        if(self::$s_tel!=NULL){
            $sql.="?,";
            array_push($params,self::$s_tel);
        }
        $sql=trim($sql,',');
        $sql.=");";
        $dbh=$db->prepare($sql);
        $dbh->execute($params);
    }
    static public function Edit($db){
        $params=array();
        $sql="update t_tel_t set ";
        if(self::$s_tel!=NULL){
            $sql.=" s_tel=?,";
            array_push($params,self::$s_tel);
        }
        $sql=trim($sql,',');
        $sql.=" where 1=1";
        if(self::$s_no!=NULL){
            $sql.=" and s_no=?";
            array_push($params,self::$s_no);
        }
        $dbh=$db->prepare($sql);
        $dbh->execute($params);
    }
    static public function Delete($db){
        $sql="delete from t_tel_t";
        $sql.=" where 1=1";
        if(self::$s_no!=NULL){
            $sql.=" and s_no=?";
            array_push($params,self::$s_no);
        }
        $dbh=$db->prepare($sql);
        $dbh->execute($params);
    }
    static public function Select(){
        $sql="select * from t_tel_t";
        return $sql;
    }
}
?>